﻿using System;
using System.IO;

namespace LiskovSubstitutionLibrary
{
    public abstract class BaseClass : IBaseInterface
    {
        protected int State;

        protected int HiddenField;

        protected void HiddenMethod()
        {
            State = 2;
        }

        public abstract void AbstractMethod();

        public virtual void BaseInterfaceMethod()
        {
            throw new NotImplementedException();
        }

        public virtual int NoBaseCall(string text)
        {
            return text.Length;
        }

        public virtual int GoodOverride(string text)
        {
            return text.Length;
        }

        public virtual int ChangeOwnState(string text)
        {
            return text.Length;
        }

        public virtual int ChangeBaseState(string text)
        {
            return text.Length;
        }

        public virtual void ReturnBeforeBaseCall(string text)
        {
            Console.WriteLine(text);
        }

        public virtual void ThrowBeforeBaseCall(string text)
        {
            if (text.Length > 100)
            {
                throw new ArgumentException();
            }
            Console.WriteLine(text);
        }

        public virtual int ReturnOtherValue(string text)
        {
            return text.Length;
        }

        public virtual Uri ReturnOtherObject(string text)
        {
            return new Uri(text);
        }

        public virtual Uri ReturnSameObject(string text)
        {
            return new Uri(text);
        }

        public override string ToString()
        {
            return "HelloWorld";
        }

        public virtual int CalledBaseMethodModifiesBaseField(string text)
        {
            return text.Length;
        }

        public virtual int CalledOwnMethodModifiesBaseField(string text)
        {
            return text.Length;
        }

        public virtual void ThrowNewExceptionType()
        {
            if (State == 1)
            {
                throw new NotImplementedException();
            }
            throw new IOException();
        }

        public virtual void ThrowBaseExceptionType()
        {
            if (State == 1)
            {
                throw new NotImplementedException();
            }
            throw new IOException();
        }

        public virtual void ThrowNewExceptionTypeInCall()
        {
            if (State == 1)
            {
                throw new NotImplementedException();
            }
            throw new IOException();
        }

        public virtual void ThrowBaseExceptionTypeInCall()
        {
            if (State == 1)
            {
                throw new NotImplementedException();
            }
            ThrowIoException();
        }

        private void ThrowIoException()
        {
            throw new IOException();
        }

        public virtual int CopyLocal(string text)
        {
            return text.Length;
        }

        public virtual int CopyLocalReturnWrong(string text)
        {
            return text.Length;
        }
    }
}
